package com.sos.entity;

import lombok.Data;

/**
 * @author 港某人
 * @date 2021/3/7 15:01
 */
@Data
public class LayuiR<T> {

    private int code = 200;
    private String msg;
    private long count;
    private T data;

    private LayuiR() {
    }

    private LayuiR(T data, String msg) {
        this.data = data;
        this.msg = msg;
    }

    private LayuiR(T data, String msg, int code) {
        this.data = data;
        this.msg = msg;
        this.code = code;
    }

    private LayuiR(T data, String msg, int code, long count) {
        this.data = data;
        this.msg = msg;
        this.code = code;
        this.count = count;
    }

    public static <T> LayuiR<T> data(T data) {
        LayuiR<T> r = new LayuiR<>(data, "");
        if (data == null) {
            r.msg = "暂无承载数据";
        }
        return r;
    }

    public static <T> LayuiR<T> data(T data, String msg) {
        return new LayuiR<>(data, msg);
    }

    public static <T> LayuiR<T> data(T data, long count) {
        LayuiR<T> r = new LayuiR<>(data, "", 0, count);
        if (data == null) {
            r.msg = "暂无承载数据";
        }
        return r;
    }

    public static LayuiR<String> msg(String msg) {
        return new LayuiR<>(null, msg);
    }

    public static LayuiR<String> msg(String msg, int code) {
        return new LayuiR<>(null, msg, code);
    }

}
